<?php
/**
 * Bug检测
 */
namespace Api;
use Kuyuan\WqCore\api\Api;
use Kuyuan\WqCore\util\Util;

class Bug extends Api
{
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * 检测当前系统是否有运行报错日志
     */
    public function existsBug()
    {
        Util::appointGet();
        $_error_log = ATTACHMENT_ROOT.KUYUAN_NAME."/global/error_log/error.log";
        Util::returns(array("code"=>0,"data"=>is_file($_error_log) ? 1 : 0));
    }

    /**
     * 发送Bug给开发者
     */
    public function sendBug()
    {
        Util::appointGet();
        $_error_log = ATTACHMENT_ROOT.KUYUAN_NAME."/global/error_log/error.log";
        $_content = "
                        <h3>站点信息</h3>
                        <p>系统信息：".php_uname()."</p>
                        <p>PHP版本：".PHP_VERSION."</p>
                        <p>域名：".$_SERVER['HTTP_HOST']."</p>
                     ";
        $_body = array(
            $_content,
            '@'.$_error_log
        );
        load()->func('communication');
        $_send_result = @ihttp_email('louie_gk@qq.com','有趣红包Bug提交',$_body);
        if($_send_result["errno"]) {
            $_result = array("code"=>900,"err_msg"=>"发送失败");
        } else {
            unlink($_error_log);
            $_result = array("code"=>0);
        }
        Util::returns($_result);
    }
}